﻿using FluentIoC.Configuration;
using QuickStart.Components;
using QuickStart.Services;

namespace QuickStart.Configuration
{
    public class IoCConfiguration : ContainerConfiguration
    {
        public IoCConfiguration()
        {
            //Example of registering a single service and it's implementor. 
            //Also shows setting the property of the component
            Register<IBarService>()
                .ImplementedBy<BarService>()
                .SetProperty<IBarService>(c => c.Test = "Hello world");

            //Example of registering a service which is generated using a factory
            //**NOTE** If the create method is on the class, not the interface then it must be virtual
            Register<IFactoryService>()
                .ImplementedBy<FactoryService>()
                .UsingFactory<FactoryFactory>(f => f.Create());

            //You can also register generic services like this
            Register(typeof (IGenericService<>))
                .ImplementedBy(typeof (GenericService<>));
                
            //Example of registering an assembly which is then implemented by another assembly
            //Also sets the conventions for both the services & components.
            //e.g. All service names must contain "Foo", and all component names will end with 1
            RegisterAssembly("QuickStart.Services")
                .ImplementedBy("QuickStart.Components")
                .UsingConventions(
                    new Conventions {
                        ServiceConventions = s => s.Name.Contains("Foo"),
                        ComponentConventions = c => false == c.Name.EndsWith("1")
                    }
                );
        }
    }
}